package com.wtgroup.demo.common.util;

import java.util.concurrent.TimeUnit;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/3/7 17:19
 */
public class SleepUtil {

    /**忽略打断的睡眠
     *
     * 精确到ms
     * @param seconds
     */
    public static void sleep(int seconds) {
        long stms = System.currentTimeMillis();
        long sleepms = seconds * 1000;
        long remainms = sleepms;
        while (remainms > 0) {
            try {
                TimeUnit.MILLISECONDS.sleep(remainms);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            remainms = sleepms - (System.currentTimeMillis() - stms);
        }
    }
}
